
//声明一个类
class Person{
  //属性
  name:string = '';
  age: number;
  height: number;

  //方法
  constructor(name: string, age: number, height:number){
    this.name = name;
    this.age = age;
    this.height = height;
  }

  //介绍自己的方法
  intro():void{
    console.log(`我叫 ${this.name} , 今年 ${this.age} , 身高 ${this.height}`)
  }
}
//实例化
// let me = new Person('xiaohigh', 35, 179.5);
// console.log(me);

class Programmer extends Person{
  //类型属性
  type: string;
  //构造方法
  constructor(name: string, age: number, height: number, type: string){
    //调用父类的构造方法
    super(name, age, height);
    //初始化
    this.type = type;
  }

  //声明一个 intro 方法
  intro(): void {
    console.log(`我叫 ${this.name} , 今年 ${this.age} , 身高 ${this.height}, 我可以编写${this.type}语言`)
  }

}

let me = new Programmer('xiaohigh', 35, 179.5, 'JavaScript');
// console.log(me);
// me.intro();



//类   进行访问控制
//继承
class Father {
  public name: string;
  protected age: number;
  private salary: number;

  constructor(name: string, age: number, salary: number){
    this.name = name;
    this.age = age;
    this.salary = salary;
  }

  info(){
    console.log(this.name);
    console.log(this.age);
    console.log(this.salary);
  }
}

class Son extends Father{

  constructor(name: string, age: number, salary: number){
    super(name, age, salary);
  }

  //声明一个方法
  access(){
    //public   √
    // console.log(this.name);
    //proteced  √
    // console.log(this.age);
    //private    X
    // console.log(this.salary);
  }
}

let xue = new Son('xue', 26, 16000);

//调用子类的方法
// xue.access();
xue.info();

//public  √
// console.log(xue.name);
//protected  X
// console.log(xue.age);
//private   X
// console.log(xue.salary);


export {};